const projectTitle = import.meta.env.VITE_APP_TITLE

// 设置网页标题
export const setPageTitle = (pageTitle: any) => {
  let title = "";
  if (pageTitle) {
    title = `${pageTitle} - ${projectTitle}`
  } else {
    title = projectTitle
  }
  document.title = title
}

// 判断{}对象是否为空
export const isObjectEmpty = (obj: any) => {
  return !obj || Object.prototype.toString.call(obj) !== '[object Object]' || Object.keys(obj).length == 0
}

// 判断数组是否为空
export const isArrayEmpty = (arr: any) => {
  return !arr || !Array.isArray(arr) || arr.length == 0
}

// 根据时间Date() 获取xx-xx-xx
export const formatDate = (date: Date, format: string = 'YYYY-MM-DD hh:mm:ss') => {
  const map: { [key: string]: number } = {
    'YYYY': date.getFullYear(),
    'MM': date.getMonth() + 1,
    'DD': date.getDate(),
    'hh': date.getHours(),
    'mm': date.getMinutes(),
    'ss': date.getSeconds(),
  }
  return format.replace(/YYYY|MM|DD|hh|mm|ss/g, (match: string) => {
    return map[match] < 10 ? '0' + map[match] : map[match] + ''
  })
}

// 获取是星期几
export const getWeek = (date: Date) => {
  const week = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六']
  return week[date.getDay()]
}